package com.xjoyt.pay.master.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;

import com.xjoyt.pay.abstracts.AbstractDao;
import com.xjoyt.pay.dto.PageParam;
import com.xjoyt.pay.dto.PageResult;
import com.xjoyt.pay.master.dao.ChannelRepositoryCustom;
import com.xjoyt.pay.master.dao.predicate.ChannelCommands;
import com.xjoyt.pay.master.params.ChannelPageParam;
import com.xjoyt.pay.master.po.Channel;
import com.xjoyt.pay.master.repository.ChannelRepository;

public class ChannelRepositoryImpl extends AbstractDao implements ChannelRepositoryCustom {

	@Autowired
	private ChannelRepository repository;

	@Override
	public PageResult<Channel> loadPage(PageParam<ChannelPageParam> param) {

		Pageable pageable = getPageable(param);
		Specification<Channel> spec = getSpecification(ChannelCommands.class, param.query);
		Page<Channel> pageResult = repository.findAll(spec, pageable);
		// if (StringUtils.isNotBlank(param.query.companyId)) {
		// pageResult = repository.findAllByCanUse(param.query.companyId,
		// pageable);
		// }
		return new PageResult<Channel>(pageResult.getTotalElements(), pageResult.getContent());
	}

}
